package com.heima.comment.controller;

import com.heima.model.comment.dtos.CommentDTO;
import com.heima.model.comment.dtos.CommentLikeDTO;
import com.heima.model.comment.dtos.CommentSaveDTO;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.comment.service.ICommentService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/api/v1/comment")
public class CommentController {

    private final ICommentService commentService;

    /** 用户进行了文章评论 */
    @PostMapping("/save")
    public ResponseResult saveComment(@Validated @RequestBody CommentSaveDTO dto){
        log.info("进行了文章评论的提交:{}",dto);
        return commentService.save(dto);
    }

    /** 查询评论列表 */
    @PostMapping("/load")
    public ResponseResult loadComment(@RequestBody CommentDTO dto){
        log.info("进行了查询评论列表");
        return commentService.load(dto);
    }

    /** 用户进行了点赞 */
    @PostMapping("/like")
    public ResponseResult likeComment(@RequestBody CommentLikeDTO dto){
        log.info("用户进行了点赞:{}",dto);
        return commentService.like(dto);
    }
}
